﻿@using Mrc.Application;
@{
    ViewData["Title"] = "LogList";
    Layout = "~/Areas/Admin/Views/_Layout.cshtml";
}

<link href="~/lib/layui/layui_ext/dtree/dtree.css" rel="stylesheet" />
<link href="~/lib/layui/layui_ext/dtree/font/dtreefont.css" rel="stylesheet" />

<table class="layui-hide" id="tabledata" lay-filter="tabledata"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="delete">清空选中表</button>
        <button class="layui-btn layui-btn-sm" onclick="javascript:location.replace(location.href);">刷新</button>
    </div>
</script>
<script>
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        table.render({
            elem: '#tabledata'
            , height: 'full-20'
            , url: '/admin/database/GetAllTable'
            , toolbar: '#toolbarDemo'
            , title: '清空数据'
            , cols: [[
                { type: 'checkbox', fixed: 'left' }
                , { field: 'name', title: '表名',sort: true }
            ]]
            , limits: [100, 200, 400]
            , limit: 100 //默认采用10
            , page: true
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
        });
        //头工具栏事件
        table.on('toolbar(tabledata)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'delete':
                    var data = checkStatus.data;
                    if (data.length < 1) {
                        layer.msg('请选择删除项');
                        break;
                    }
                    else {
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].name);
                        }
                        console.table(ids);
                        BaseAjax(ajaxType.post, "/admin/database/ClearTables", { tables: ids }, function (repo) {
                            if (repo.status == ajaxStatus.OK) {
                                table.reload('tabledata', { page: { curr: 1 } });
                            }
                        });
                    }
                    break;
            };
        });
    })
</script>
